OPERATING SYSTEMS - FALL 2011 ============================= Assignment I ------------ Students: Radutiu victor, Petcov Petru, Rusu Vlad -------------------------------------------------------------------------- -- IMPORTANT -- !!! ALL YOUR CODE MUST BE WRITTEN IN ANSI C99 !!! -------- -------------------------------------------------------------------------- Scope: create a simple command line interpretor, able to interpret a set of internally-implemented commands. Your task for this task assignment is to create a simple command line interpretor. The command line interpretor will offer the following facilities: * Accept user commands from command line. The interpretor will expose a specific prompt (e.g. '$>') showing that it is prepared to accept a user command. * Execute user commands, from the list of accepted commands. The following error situations MUST be considered: o Command execution returned an error. The exact error code must be reported. o Issued command is not an accepted command. Error information will contain 'offending' command name. o Arguments are in a wrong format: the only accepted format is "-o ARG", where ARG is the optional argument of your option. It is not accepted to use the '/' notation for options or the --option long notation for options. These errors should be identified during preprocessing of command line. * Maintain and manage some environmental information, including the root directory, current directory, prompt, or environmental variables (some of the implemented commands will address these issues). * Offer a command called "help", that will list all available commands with implemented options. * Offer a command called "version", that will offer author information, versioning information, and possibly other valuable information. * All commands will be implemented as external functions. A library of functions could be developed for this purpose. o Each command will accept the main calling convention: int yourCommandFunction (int argc, char *argv[]) ;. Implementation of the additional main parameter (char **envp) is not required. o Each command will return success or an error code (see error code manipulation, above). o Each command could report additional error information prior to command exit. E.g. a command that opens an existing file will report the fact that the file does not exist or that it has no permission to access the file. The following commands must be implemented, along with their parameters (see man help pages for information on each): 1. The "cat" command. Parameters that need to be implemented are: -b -E -n -s 2. The "tee" command. Parameters that need to be implemented are: -a 3. The "yes" command. No parameters need to be implemented. Additional Requirements (Assignment II) --------------------------------------- Scope: implementing command line parsing in your simple command line interpretor (previously developed in Assignment #1). Your newly created application will be able now to execute complex command lines. The following commands must be implemented, in addition to the commands from Assignment I, along with their parameters (see man help pages for information on each): 1. The "ls" command. Parameters that need to be implemented are: -l, -s, -a, -F 2. The "tac" command. Parameters that need to be implemented are: -b, -s 3. The "dir" command. No parameters need to be implemented. Additional Requirements (Assignment III) ---------------------------------------- Your task for this task assignment is to change your previously developed simple command line interpretor. The new facilities developed will include the following: * Using the ';' separator in command line: with this construction you are able to specify several commands to be executed, one after the other, in your command line. * Using the '&&' and '||' separators: with these constructions you can implement conditional executions, where second command will be executed only if previous was successful or failed. Please notice that execution result is important for this implementation. Your shell should retain the execution result (return code) for all command lines! * Using the simple redirect mechanism, '>', '<': with I/O redirection your commands are now able to change the meaning of stdin and stdout devices. * Using the PIPE mechanism, '|': with the pipe mechanism you can "interconnect" two (or several) commands. PIPE is based on I/O redirection, so redirection should be solved first. * Execution of external commands: you are going to enable execution of external commands. Please notice that your shell should check if a specified command exist as an internal command before executing the external command! * Also, partial implementations of other commands should be completed during this assignment. E.g. if not all options were implemented, please continue implementation now! Some information about the UNIX command line. 1. cmd1 ; cmd2; cmd3; cmd4. Sequential execution of commands. Like when the commands were specified on successive lines. After this execution your shell should retain return code of your last command. Each command could be a simple command OR a complex command line (like those specified on this page) 2. cmd1 && cmd2. Second command should be executed when first command was successful. Also, your shell should be able to perform executions like cmd1; cmd2 && cmd2a ; cmd3 .... After this execution your shell should retain return code of last executed command! 3. cmd1 || cmd2. Second command should be executed when first command failed Also, your shell should be able to perform executions like cmd1; cmd2 || cmd2a ; cmd3 .... After this execution your shell should retain return code of last executed command! 4. cmd1 > file_out. The command will redirect stdout to specified file. If file does not exist, it is created. If file exist, overwrite will happen. Report error if file cannot be created. After this execution your shell should retain return code of cmd1! 5. cmd1 < file_in. The command will redirect stdin from specified file. If file does not exist, error situation is reported. If file cannot be read, error situation is reported. After this execution your shell should retain return code of cmd1! 6. cmd1 < file_in > file_out OR cmd1 > file_out < file_in. The command will redirect stdin from specified file, and stdout to specified file. Error situations are as specified before! Please notice that executions like cmd1 ; cmd2 > file_out < file_in; cmd3 are possible, and redirection will affect ONLY cmd2. Also, in the case of cmd1 > file_out && cmd2 < file_in, for example, redirect operations are affecting cmd1 (output) and cmd2 (input). 7. cmd1 | cmd2. The command line will connect output of cmd1 to input of cmd2. After this execution your shell should retain return code of cmd2! Other usage examples: cmd1 ; cmd2 | cmd2a ; cmd3: output of cmd1 is not part of PIPE redirection. cmd1 | cmd1a && cmd2 cmd2 execution depends on result of cmd1 | cmd1a IMPORTANT --------- 1. The project is considered fully working and is graded the maximum number of points when both requirements from Assignment I and Assignment II are met. If you do not implement any of the Assignment II requirements, no credit will be given, even if the requirements of the original Assignment I are met. 2. Your final grade will be computed as: 10 points (by default) + Number_of_Points_for_Project_I (25 points maximum) + Number_of_Points_for_Project_II (40 points maximum) + Number_of_Points_for_Project_III (25 points maximum) 3. The minimum number of points required to pass the Operating Systems laboratory is 50 points. Documentation ------------- 1. All commands implemented must be properly documented. This means their syntax needs to be presented, each parameter as well as an exhaustive description of what each parameter does and at least an example of usage for it. 2. The implementation method must be defined. You must explain how you developed the system, why you have made each development choice and how performance could be improved if case. 3. You MUST keep the structure of the paper, in LaTeX, similar to the structure of a diploma thesis paper. A template that could be helpful may be found at: http://web.mit.edu/rwcox/Thesis/ 4. Very important: specify ALL references properly and add them to your bibliography! 5. Each assignment requires a minimum of 15 A4 pages of documentation to be written in LaTeX and a maximum of 25 A4 pages. ------------------------------------------------------------------------------------------------------------------------------------------ IMPORTANT: No delays of any reason are accepted. A project that has not been delivered by the deadline is awarded 0 points. NO EXCEPTIONS. ------------------------------------------------------------------------------------------------------------------------------------------